<template>
  <div class="common-layout">
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="aSideWidth" class="sider-container">
        <div class="logo-container">
          <img src="../../../assets/logo.svg" class="logo-img" />
          <transition name="fade">
            <span v-if="!collapse" class="logo-text">言㐱陪诊 大数据展示系统</span>
          </transition>
        </div>

        <el-menu
            default-active="1"
            class="el-menu-vertical-demo"
            background-color="#1a1a1a"
            active-text-color="#40b782"
            text-color="#b0b0b0"
            :collapse="collapse"
            :collapse-transition="false"
            router
        >
          <!-- 菜单项 -->
          <el-menu-item index="home">
            <el-icon><House /></el-icon>
            <template #title>
              <span>首页</span>
              <div class="menu-hover-effect"></div>
            </template>
          </el-menu-item>

          <el-menu-item index="login">
            <el-icon><SwitchButton /></el-icon>
            <template #title>
              <span>切换账户</span>
              <div class="menu-hover-effect"></div>
            </template>
          </el-menu-item>

          <!-- 陪诊护士管理 -->
          <el-sub-menu index="2">
            <template #title>
              <el-icon><UserFilled /></el-icon>
              <span>陪诊护士管理</span>
              <div class="menu-hover-effect"></div>
            </template>
            <el-menu-item index="escort" class="sub-menu-item">
              <el-icon><User /></el-icon>
              <span>护士信息管理</span>
            </el-menu-item>
          </el-sub-menu>

          <!-- 客户管理 -->
          <el-sub-menu index="3">
            <template #title>
              <el-icon><UserFilled /></el-icon>
              <span>客户管理</span>
              <div class="menu-hover-effect"></div>
            </template>
            <el-menu-item index="patient" class="sub-menu-item">
              <el-icon><User /></el-icon>
              <span>客户信息管理</span>
            </el-menu-item>
          </el-sub-menu>


          <!-- 预约管理 -->
          <el-sub-menu index="4">
            <template #title>
              <el-icon><Location /></el-icon>
              <span>预约管理</span>
              <div class="menu-hover-effect"></div>
            </template>
            <el-menu-item index="appointment" class="sub-menu-item">
              <el-icon><Document /></el-icon>
              <span>预约表信息管理</span>
            </el-menu-item>
            <el-menu-item index="appointment2" class="sub-menu-item">
              <el-icon><Document /></el-icon>
              <span>预约表信息管理2</span>
            </el-menu-item>
          </el-sub-menu>

          <!-- 服务记录管理 -->
          <el-sub-menu index="5">
            <template #title>
              <el-icon><Document /></el-icon>
              <span>服务记录管理</span>
              <div class="menu-hover-effect"></div>
            </template>
            <el-menu-item index="serviceRecord" class="sub-menu-item">
              <el-icon><Document /></el-icon>
              <span>服务记录表信息管理</span>
            </el-menu-item>
          </el-sub-menu>

          <!-- 账号管理 -->
          <el-sub-menu index="6">
            <template #title>
              <el-icon><Setting /></el-icon>
              <span>账号管理</span>
              <div class="menu-hover-effect"></div>
            </template>
            <el-menu-item index="user" class="sub-menu-item">
              <el-icon><User /></el-icon>
              <span>全部账号管理</span>
            </el-menu-item>
            <el-menu-item index="user0" class="sub-menu-item">
              <el-icon><User /></el-icon>
              <span>管理员管理</span>
            </el-menu-item>
            <el-menu-item index="user1" class="sub-menu-item">
              <el-icon><User /></el-icon>
              <span>陪诊护士管理</span>
            </el-menu-item>
            <el-menu-item index="user2" class="sub-menu-item">
              <el-icon><User /></el-icon>
              <span>用户管理</span>
            </el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>

      <el-container>
        <!-- 头部 -->
        <el-header class="header-container">
          <div class="header-left">
            <el-tooltip :content="collapse ? '展开菜单' : '折叠菜单'">
              <el-icon :size="20" class="fold-icon" @click="toggleCollapse">
                <component :is="collapse ? Expand : Fold" />
              </el-icon>
            </el-tooltip>
          </div>

          <div class="header-right">
            <el-dropdown>
              <div class="user-info">
                <el-avatar :size="36" src="../../../assets/touxiang.png" class="avatar" />
                <transition name="fade">
                  <span v-if="!collapse" class="username">管理员</span>
                </transition>
              </div>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>个人中心</el-dropdown-item>
                  <el-dropdown-item>退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </el-header>

        <!-- 主体内容 -->
        <el-main class="main-container">
          <div class="content-wrapper">
            <router-view v-slot="{ Component }">
              <transition name="fade-transform" mode="out-in">
                <component :is="Component" />
              </transition>
            </router-view>
          </div>
        </el-main>

        <!-- 页脚 -->
        <el-footer class="footer-container">
          <div class="footer-content">
            <el-icon><DocumentCopy /></el-icon>
            <span>2024 言㐱陪诊系统 - 专业：计算机科学与技术 班级：计技222班</span>
            <el-divider direction="vertical" />
            <span>学号：2022102207 姓名：吴玉海</span>
          </div>
        </el-footer>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  Fold,
  Expand,
  House,
  UserFilled,
  SwitchButton,
  DocumentCopy,
  Location,
  Setting,
  Document,
  User // 引入缺失的图标
} from '@element-plus/icons-vue'

const aSideWidth = ref('250px')
const collapse = ref(false)

const toggleCollapse = () => {
  collapse.value = !collapse.value
  aSideWidth.value = collapse.value ? '64px' : '250px'
}
</script>

<style scoped lang="scss">
.common-layout {
  height: 100vh;
  background: #f0f2f5;
}

// 侧边栏样式
.sider-container {
  background: #1a1a1a;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);

  .logo-container {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: #121212;
    overflow: hidden;

    .logo-img {
      width: 36px;
      height: 36px;
      margin-right: 12px;
    }

    .logo-text {
      color: #40b782;
      font-size: 18px;
      font-weight: 600;
      white-space: nowrap;
    }
  }

  /*  .el-menu {
      border-right: none;

      !* 兼容不同 Vue 版本的深度选择器 *!
      ::v-deep(.el-menu-item),
      ::v-deep(.el-sub-menu__title) {
        height: 48px;
        line-height: 48px;
        transition: all 0.3s;

        &:hover {
          background: rgba(64, 183, 130, 0.1) !important;

          .menu-hover-effect {
            width: 100%;
          }
        }
      }

      .sub-menu-item {
        padding-left: 50px !important;
        background: #252525 !important;

        &:hover {
          background: rgba(64, 183, 130, 0.05) !important;
        }
      }
    }*/
  .el-menu {
    border-right: none;

    /* 使用 :deep() 替代 ::v-deep */
    :deep(.el-menu-item),
    :deep(.el-sub-menu__title) {
      height: 48px;
      line-height: 48px;
      transition: all 0.3s;

      &:hover {
        background: rgba(64, 183, 130, 0.1) !important;

        .menu-hover-effect {
          width: 100%;
        }
      }
    }

    .sub-menu-item {
      padding-left: 50px !important;
      background: #252525 !important;

      &:hover {
        background: rgba(64, 183, 130, 0.05) !important;
      }
    }
  }
}

.menu-hover-effect {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, #40b782, #63e2b7);
  transition: width 0.3s;
}

// 头部样式
.header-container {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);

  .fold-icon {
    cursor: pointer;
    transition: transform 0.3s;

    &:hover {
      transform: scale(1.1);
    }
  }

  .user-info {
    display: flex;
    align-items: center;
    cursor: pointer;

    .username {
      margin-left: 12px;
      font-size: 14px;
    }
  }

  .avatar {
    transition: transform 0.3s;

    &:hover {
      transform: scale(1.1);
    }
  }
}

// 主体内容
.main-container {
  padding: 20px;

  .content-wrapper {
    background: #ffffff;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    min-height: calc(100vh - 120px);
  }
}

// 页脚样式
.footer-container {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: #666;
  font-size: 14px;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);

  .footer-content {
    display: flex;
    align-items: center;

    .el-divider {
      margin: 0 16px;
      background-color: #ddd;
    }
  }
}

// 过渡动画
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.fade-transform-enter-active,
.fade-transform-leave-active {
  transition: all 0.3s;
}

.fade-transform-enter-from {
  opacity: 0;
  transform: translateX(-30px);
}

.fade-transform-leave-to {
  opacity: 0;
  transform: translateX(30px);
}
</style>